package com.example.userservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.userservice.entity.VolunteerProfile;
import com.example.userservice.mapper.VolunteerProfileMapper;
import com.example.userservice.service.VolunteerProfileService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class VolunteerProfileServiceImpl extends ServiceImpl<VolunteerProfileMapper, VolunteerProfile> implements VolunteerProfileService {

    @Override
    public IPage<VolunteerProfile> pageProfiles(Integer current, Integer size, Map<String, Object> params) {
        Page<VolunteerProfile> page = new Page<>(current, size);
        QueryWrapper<VolunteerProfile> wrapper = new QueryWrapper<>();

        // 动态条件查询
        if (params.containsKey("realName") && params.get("realName") != null) {
            wrapper.like("real_name", params.get("realName"));
        }
        if (params.containsKey("school") && params.get("school") != null) {
            wrapper.like("school", params.get("school"));
        }
        if (params.containsKey("status") && params.get("status") != null) {
            wrapper.eq("status", params.get("status"));
        }

        return page(page, wrapper);
    }
}
